float4x4 World;
float4x4 View;
float4x4 Projection;

float nColHeightMap;
float nRowHeightMap;

float2 PointIndex;

texture WaterTexture;
sampler WaterTextureSampler = sampler_state 
						{
							texture = <WaterTexture>; 
							magfilter = LINEAR;
							minfilter = LINEAR; 
							mipfilter = LINEAR; 
							AddressU = clamp; 
							AddressV = clamp; 
						};

texture GrassTexture;
sampler GrassTextureSampler = sampler_state 
						{
							texture = <GrassTexture>; 
							magfilter = LINEAR;
							minfilter = LINEAR; 
							mipfilter = LINEAR; 
							AddressU = clamp; 
							AddressV = clamp; 
						};

texture GroundTexture;
sampler GroundTextureSampler = sampler_state 
						{
							texture = <GroundTexture>; 
							magfilter = LINEAR;
							minfilter = LINEAR; 
							mipfilter = LINEAR; 
							AddressU = clamp; 
							AddressV = clamp; 
						};

texture SnowTexture;
sampler SnowTextureSampler = sampler_state 
						{
							texture = <SnowTexture>; 
							magfilter = LINEAR;
							minfilter = LINEAR; 
							mipfilter = LINEAR; 
							AddressU = clamp; 
							AddressV = clamp; 
						};

// TODO: add effect parameters here.

struct VertexShaderInput
{
    float4 Position : POSITION0;

    // TODO: add input channels such as texture
    // coordinates and vertex colors here.
};

struct VertexShaderOutput
{
    float4 Position : POSITION0;
	float4 MyData : COLOR0;

    // TODO: add vertex shader outputs such as colors and texture
    // coordinates here. These values will automatically be interpolated
    // over the triangle, and provided as input to your pixel shader.
};

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;

    float4 worldPosition = mul(input.Position, World);
    float4 viewPosition = mul(worldPosition, View);
    output.Position = mul(viewPosition, Projection);
	
	if(input.Position.y < 10)
		input.Position.y = 10;
	//input.Position.y -= 3;

	output.MyData = 0;
	output.MyData.r = (input.Position.x) / nColHeightMap;
	output.MyData.g = input.Position.y/64;
	output.MyData.b = (input.Position.z) / nRowHeightMap;

    // TODO: add your vertex shader code here.

    return output;
}

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
    // TODO: add your pixel shader code here.
	float h = input.MyData.g*40;
	float4 Color;
	float2 ToaDo = float2(input.MyData.r, input.MyData.b);
	float4 Water = tex2D(WaterTextureSampler, ToaDo);
	float4 Grass = tex2D(GrassTextureSampler, ToaDo);
	float4 Ground = tex2D(GroundTextureSampler, ToaDo);
	float4 Snow =  tex2D(SnowTextureSampler, ToaDo);
	float heso;
	if(h <= 10)
	{
		heso = h/10;
		Color = (1-heso) * Water + heso * Grass;
	}
	else if(h <= 20)
	{
		heso = (h-10)/10;
		Color = (1-heso) * Grass + heso * Ground;
	}
	else if(h <= 30)
	{
		heso = (h-20)/10;
		Color = (1-heso) * Ground + heso * Snow;
	}
	else
	{
		Color = Snow;
	}
    return Color;
}

technique Technique1
{
    pass Pass1
    {
        // TODO: set renderstates here.

        VertexShader = compile vs_2_0 VertexShaderFunction();
        PixelShader = compile ps_2_0 PixelShaderFunction();
    }
}
